home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #2
/
Amiga Plus CD - 1999 - No. 2.iso
/
System-Boost
/
Workbench
/
Archive
/
XPK
/
xpk_Source
/
test
/
testMemPack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-11-15
|
2KB
|
93 lines
#define NAME "testMemPack"
#define DISTRIBUTION "(Freeware) "
#define REVISION "4"
#define SDI_ENDCODE_NOCTRLC
/* Programmheader
Name: testMemPack
Author: SDI
Distribution: Freeware
Description: tests Xpk Pack function
Compileropts: -
Linkeropts: -l xpkmaster amiga
1.1 06.12.96 : fixed for new includes, added new WriteXpkFib
1.2 28.12.96 : changed TO/A to TO
1.3 15.04.97 : removed WriteXpkFib.c
1.4 28.11.97 : moved chunk-hook into include file
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/xpkmaster.h>
#include <exec/memory.h>
#include "SDI_defines.h"
#include "chunkhook.c"
struct Library *XpkBase = 0;
ULONG DosVersion = 37;
STRPTR ibuf = 0,
obuf = 0;
ULONG ibuflen = 0,
obuflen = 0;
BPTR fh = 0;
struct RDArgs *rda = 0;
struct FileInfoBlock *fib = 0;
#define PARAM "FROM/A,TO,METHOD"
void main(void)
{
UBYTE errbuf[XPKERRMSGSIZE+1];
ULONG olen;
struct {
STRPTR from;
STRPTR to;
STRPTR method;
} args = {0,0,"USER"};
if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
!(XpkBase = OpenLibrary(XPKNAME, 0)) ||
!(fh = Open(args.from, MODE_OLDFILE)) ||
!(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
!(ExamineFH(fh, fib)) ||
!(ibuf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
Read(fh, ibuf, fib->fib_Size) != fib->fib_Size)
End(RETURN_FAIL);
ibuflen = fib->fib_Size;
Close(fh); fh = 0;
if(XpkPackTags(XPK_InBuf, ibuf, XPK_InLen, ibuflen,
XPK_PackMethod, args.method, XPK_GetOutBuf,
&obuf, XPK_GetOutBufLen, &obuflen, XPK_GetOutLen, &olen,
XPK_GetError, errbuf, XPK_ChunkHook, &chunkhook, TAG_DONE))
{
STRPTR a = errbuf;
VPrintf("Can't XpkPack: %s\n", &a);
End(RETURN_FAIL);
}
if(args.to)
{
if(!(fh = Open(args.to, MODE_NEWFILE)) ||
Write(fh, obuf, olen) != olen)
End(RETURN_FAIL);
}
End(RETURN_OK);
}
void end(void)
{
if(fh) Close(fh);
if(XpkBase) CloseLibrary(XpkBase);
if(fib) FreeDosObject(DOS_FIB, fib);
if(rda) FreeArgs(rda);
if(ibuf) FreeMem(ibuf, ibuflen);
if(obuf) FreeMem(obuf, obuflen);
}